package com.atguigu.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.feignapis.PayFeignApi;
import com.atguigu.cloud.resp.ResultData;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.TimeUnit;

/**
 * @auther zzyy
 * @create 2023-11-04 16:00
 */
@RestController
@Slf4j
public class OrderController {
    @Resource
    private PayFeignApi payFeignApi;


    @GetMapping(value = "/consumer/pay/get/info")
    public String getInfoByConsul(){
        return payFeignApi.getYamlInfo();
    }

    @GetMapping(value = "/consumer/pay/getPayById/{id}")
    public ResultData getPayById(@PathVariable("id") Integer id)
    {
        return payFeignApi.getPayById(id);
    }

    @PostMapping("/consumer/pay/add")
    public ResultData createPay(@RequestBody PayDTO payDTO)
    {
        return payFeignApi.addPay(payDTO);
    }

    @GetMapping("/consumer/pay/getPayList")
    public ResultData getPayList()
    {
        return payFeignApi.getAllList();
    }

    @GetMapping("/consumer/pay/connectTimeOut")
    public ResultData connectTimeOut() {
        ResultData resultData = null;
        try {
            log.info("调用8001端口的connectTimeOut方法开始时间:{}" , DateUtil.now());
            resultData = payFeignApi.connectTimeOut();
        } catch (Exception e) {
            resultData = new ResultData<>()
                    .setCode("500")
                    .setMessage("调用8001端口的connectTimeOut方法异常:"+e.getMessage());
            e.printStackTrace();
        }finally {
            log.info("调用8001端口的connectTimeOut方法结束时间:{}" , DateUtil.now());
            return resultData;
        }

    }

}

